package com.example.library;

import android.content.Context;

import com.example.library.http.ApiMethods;
import com.example.library.http.KnowledgeEntity;
import com.example.library.http.KnowledgeParseEntity;
import com.example.library.http.MyObserver;
import com.example.library.http.ObserverOnNextListener;
import com.google.gson.JsonObject;
import com.orhanobut.logger.Logger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dadong on 2018/8/29.
 * Describe:
 */
public class RequestKnowledgeEntity {

    Context context;
    RequestBack requestBack;

    public RequestKnowledgeEntity(Context context, RequestBack requestBack) {
        this.context = context;
        this.requestBack = requestBack;
    }

    List<KnowledgeEntity> entities = new ArrayList<>();

    public void getData(final String text, String leveCode) {
        ObserverOnNextListener<List<KnowledgeEntity>> listener = new ObserverOnNextListener<List<KnowledgeEntity>>() {
            @Override
            public void onNext(List<KnowledgeEntity> knowledgeEntities) {
                if (knowledgeEntities != null && knowledgeEntities.size() > 0) {
                    entities.addAll(knowledgeEntities);
                    requestBack.onSuccess(knowledgeEntities);
                }
            }

            @Override
            public void onErr(Throwable e) {
                requestBack.onErr(e);
                Logger.d("shishisaonian" + e.getMessage());
            }
        };
        ApiMethods.getKnowledge(new MyObserver<List<KnowledgeEntity>>(context, listener), text, leveCode);
    }
}
